using Controls;
using UnityEngine;
using PrimeTween;

namespace UI
{
    public class TutorialUi : MonoBehaviour
    {
        [SerializeField] private PlayerController playerController;
        
        [SerializeField] private CanvasGroup moveTip;
        [SerializeField] private CanvasGroup shootTip;
        [SerializeField] private CanvasGroup tip1;

        private readonly float _fadeTime = 0.5f;
        

        private void Awake()
        {
            playerController.MovePerformed += PlayerController_MovePerformed;
            
            shootTip.alpha = 0;
            tip1.alpha = 0;
        }
        
        private void PlayerController_ShootPerformed()
        {
            playerController.ShootPerformed -= PlayerController_ShootPerformed;

            HideTip(shootTip, _fadeTime);
            Tween.Delay(1f, () => ShowTip(tip1, 2f));
            Tween.Delay(5f, () =>
            {
                HideTip(tip1, 2f);
            });
        }

        private void PlayerController_MovePerformed()
        {
            playerController.MovePerformed -= PlayerController_MovePerformed;
            playerController.ShootPerformed += PlayerController_ShootPerformed;

            HideTip(moveTip, _fadeTime);
            ShowTip(shootTip, _fadeTime);
        }

        private Tween ShowTip(CanvasGroup tip, float duration)
        {
            return Tween.Alpha(tip, 1f, duration);
        }
        
        private Tween HideTip(CanvasGroup tip, float duration)
        {
            return Tween.Alpha(tip, 0f, duration);
        }
    }
}